<?php echo $this->headLink()->appendStylesheet('/jquery/jquery.rte1_2/jquery.rte.css'); ?>
<?php echo $this->headLink()->appendStylesheet('/css/redmond/jquery-ui-1.8.5.custom.css') ?>
<?php echo $this->headLink()->appendStylesheet('/css/prodform.css'); ?>
<script type="text/javascript" src="/jquery/jquery.rte1_2/jquery.rte.comment.js"></script>
<script type="text/javascript" src="/jquery/jquery.rte1_2/jquery.rte.tb.comment.js"></script>
<script type="text/javascript" src="/jquery/jquery.rte1_2/jquery.ocupload-1.1.4.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	var arr = $('.rte1').rte({
		controls_rte: rte_toolbar,
		controls_html: html_toolbar
	});

	$("#prodForm").validate({
    	highlight: function(element, errorClass) {
        	$(element).css({ backgroundColor: "rgb(240,150,150)"});
        },
        unhighlight: function(element, errorClass) {
            $(element).css({ backgroundColor: "rgb(160,255,165)"});
        },
        rules: 
        {
        	"product": {
        		required: true
            },
            "quantity": {
        		required: true,
        		digits: true
            },
            "status": {
        		required: true,
        		digits: true
            },
            "price": {
            	required: true,
        		digits: true
            },
            "day": {
            	required: true,
        		digits: true
            },
            "imgFile": {
            	accept: "jpeg|jpg|JPG|JPEG"
            },
            "subImgFile1": {
            	accept: "jpeg|jpg|JPG|JPEG"
            },
            "subImgFile2": {
            	accept: "jpeg|jpg|JPG|JPEG"
            }
        },
        messages: {
            "product": {
           		required: "請輸入物品名稱"
            },
            "quantity": {
           		required: "請輸入數量",
           		digits: "請輸入數字"
            },
            "status": {
           		required: "請輸入新淨度",
           		digits: "請輸入數字"
            },
            "price": {
           		required: "請輸入價錢",
           		digits: "請輸入數字"
            },
            "day": {
           		required: "請輸入刊登日數",
           		digits: "請輸入數字"
            },
            "imgFile": {
            	accept: "請上傳JPG及JPEG格式圖片"
            },
            "subImgFile1": {
            	accept: "請上傳JPG及JPEG格式圖片"
            },
            "subImgFile2": {
            	accept: "請上傳JPG及JPEG格式圖片"
            }
        }
    });



	$("#btnNext1").click(function(){		
		if($("#prodForm").validate().element("#txtProduct")
			&& $("#prodForm").validate().element("#txtQuantity")
			&& $("#prodForm").validate().element("#txtStatus")){
			$("#tblPart1").hide();
			$("#imgStep1").hide();
			$("#tblPart2").show();
			$("#imgStep2").show();
		}
	});
	$("#btnNext2").click(function(){
		if($("#prodForm").validate().element("#imgImgFile")
			&& $("#prodForm").validate().element("#imgSubImgFile1")
			&& $("#prodForm").validate().element("#imgSubImgFile2")){
			$("#tblPart2").hide();
			$("#imgStep2").hide();
			$("#tblPart3").show();
			$("#imgStep3").show();
		}
	});
	$("#btnBack1").click(function(){
		$("#tblPart1").show();
		$("#imgStep1").show();
		$("#tblPart2").hide();
		$("#imgStep2").hide();
	});
	$("#btnBack2").click(function(){
		$("#tblPart2").show();
		$("#imgStep2").show();
		$("#tblPart3").hide();
		$("#imgStep3").hide();
	});

	$('#ddlCountry').live('change', function(){
		if (window.XMLHttpRequest){
			/*** code for IE7+, Firefox, Chrome, Opera, Safari ***/
		  	xmlhttp=new XMLHttpRequest();
		}
		else{
			/*** code for IE6, IE5 ***/
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4 && xmlhttp.status==200){
		    	document.getElementById("ajaxTag").innerHTML=xmlhttp.responseText;
		    }
		}
		xmlhttp.open("GET","/ajax/showTagList.php?country=" + $(this).val(), true);
		xmlhttp.send();
	});
});
</script>
<div id="global">
	<?php require_once '/template/left-sidebar.phtml';?>
	<div id="content-with-twoside">
		<div style="float:left;">
			<label id="lblTitle"><?php echo $this->escape($this->title);?></label>
		</div>
		<div style="float:right;">
			<img id="imgStep1" src="/images/layout/post_step1.jpg" width="260">
			<img id="imgStep2" src="/images/layout/post_step2.jpg" width="260">
			<img id="imgStep3" src="/images/layout/post_step3.jpg" width="260">
		</div>
		<br/><br/>
		<form id="prodForm" method='post' action='<?php echo $this->escape($this->action); ?>' enctype='multipart/form-data'>
			<table id="tblPart1">
				<tr>
					<td>
						<label><?php echo $this->escape($this->product);?></label>
						<br/>
						<input id="txtProduct" type="text" name="product" size="21" maxlength="20" value="<?php echo $this->escape($this->productVal);?>"/>
					</td>
					<td>
						<label><?php echo $this->escape($this->quantity);?></label>
						<br/>
						<input id="txtQuantity" type="text" name="quantity" size="3" maxlength="2" value="<?php echo $this->escape($this->quantityVal);?>"/>
					</td>
					<td>
						<label><?php echo $this->escape($this->status);?></label>
						<br/>
						<input id="txtStatus" type="text" name="status" size="3" maxlength="3" value="<?php echo $this->escape($this->newVal);?>"/>%
					</td>
					<td rowspan="3" style="vertical-align: top;">
						<div id="ajaxTag">
						
						</div>
					</td>
				</tr>
				<tr>
					<td>
						<label><?php echo $this->escape($this->tag);?></label>
						<br/>
						<input type="text" name="tag" size="21" maxlength="20"/>
					</td>
					<td colspan="2">
						<label><?php echo $this->escape($this->country);?></label>
						<br/>
						<select id="ddlCountry" name="country">
							<option value="">選擇地點</option>
							<?php 
							for($i = 0;$i < sizeof($this->countryEntries); $i++){
							?>
							<option value="<?php echo $this->countryEntries[$i]->abbrev;?>" 
								<?php if($this->countryEntries[$i]->abbrev == $this->escape($this->countryVal)){echo "selected";}?>>
								<?php echo $this->countryEntries[$i]->country_name;?>
							</option>
							<?php 
							}
							?>
						</select>
					</td>
				</tr>
				<tr>
					<td colspan="3">
						<select multiple="multiple" name="category">
						<?php
						for($i=0; $i<sizeof($this->categoryEntries); $i++){
							echo "<option value='" . $this->categoryEntries[$i]->abbrev . "'>";
							echo $this->categoryEntries[$i]->category;
							echo "</option>";
						} 
						?>
						</select>
					</td>
				</tr>
				<tr>
					<td colspan="3">
						<input id="btnNext1" class="yellow-button" type="button" value="<?php echo $this->escape($this->next);?>">
					</td>
				</tr>
			</table>
			<table id="tblPart2">
				<tr>
					<td>
						<label><?php echo $this->escape($this->description);?></label>
						<br/>
						<textarea name="description" cols="30" rows="15" class="rte1"><?php echo $this->escape($this->descriptionVal);?></textarea>
					</td>
				</tr>
				<tr>
					<td>
						<label><?php echo $this->escape($this->image);?></label>
						<input type="file" id="imgImgFile" name="imgFile">
					</td>
				</tr>
				<tr>
					<td>
						<label><?php echo $this->escape($this->subImage);?>1</label>
						<input type="file" id="imgSubImgFile1" name="subImgFile1">
					</td>
				</tr>
				<tr>
					<td>
						<label><?php echo $this->escape($this->subImage);?>2</label>
						<input type="file" id="imgSubImgFile2" name="subImgFile2">
					</td>
				</tr>
				<tr>
					<td>
						<input id="btnBack1" class="yellow-button" type="button" value="<?php echo $this->escape($this->back);?>">
						<input id="btnNext2" class="yellow-button" type="button" value="<?php echo $this->escape($this->next);?>">
					</td>
				</tr>
			</table>
			<table id="tblPart3">
				<tr>
					<td style="width: 40px;"><label><?php echo $this->escape($this->price);?></label></td>
					<td style="width: 400px;">
						<input type="text" id="txtPrice" name="price" size="10" maxlength="5" value="<?php echo $this->escape($this->priceVal);?>" placeholder="HKD"/>
					</td>
				</tr>
				<tr>
					<td><label><?php echo $this->escape($this->validDate);?></label></td>
					<td><input type="text" name="day" size="1" maxlength="2" value="<?php echo $this->escape($this->dayVal);?>"/><?php echo $this->day;?></td>
				</tr>
				<tr>
					<td><label><?php echo $this->escape($this->delivery);?></label></td>
					<td>
						<input type="radio" name="deliveryGroup" value="f" <?php if($this->escape($this->deliveryVal)=='f' || 
							($this->escape($this->deliveryVal)!='f' && $this->escape($this->deliveryVal)!= 'm')){echo "checked";}?>>
						<label><?php echo $this->face;?></label>&nbsp;
						<input type="radio" name="deliveryGroup" value="m" <?php if($this->escape($this->deliveryVal)=='m'){echo "checked";}?>>
						<label><?php echo $this->mail;?></label>&nbsp;
					</td>
				</tr>
				<tr>
					<td><label><?php echo $this->escape($this->tradeMethod);?></label></td>
					<td>
						<input type="radio" name="payGroup" value="pf" <?php if($this->escape($this->tradeVal)=='pf' || 
							($this->escape($this->tradeVal)!='pf' && $this->escape($this->tradeVal)!= 'pl') && $this->escape($this->tradeVal)!= 'pd'){echo "checked";}?>>
						<label><?php echo $this->payFirst;?></label>&nbsp;
						<input type="radio" name="payGroup" value="pl" <?php if($this->escape($this->tradeVal)=='pl'){echo "checked";}?>>
						<label><?php echo $this->payLater;?></label>&nbsp;
						<input type="radio" name="payGroup" value="pd" <?php if($this->escape($this->tradeVal)=='pd'){echo "checked";}?>>
						<label><?php echo $this->payDeposit;?></label>
						<input type="text" name="deposit" value="<?php echo $this->escape($this->depositVal);?>" size="1" maxlength="2">%
					</td>
				</tr>
				<tr>
					<td><label><?php echo $this->escape($this->payment);?></label></td>
					<td>
						<input type="checkbox" name="paypal" value="Y" <?php if($this->escape($this->paypalVal)=='Y'){echo "checked";}?>><?php echo $this->escape($this->paypal);?>&nbsp;
						<input type="checkbox" name="bank" value="Y" <?php if($this->escape($this->bankVal)=='Y'){echo "checked";}?>><?php echo $this->escape($this->bankTransfer);?>&nbsp;
						<input type="checkbox" name="cheque" value="Y" <?php if($this->escape($this->chequeVal)=='Y'){echo "checked";}?>><?php echo $this->escape($this->cheque);?>&nbsp;
						<input type="checkbox" name="others" value="Y" <?php if($this->escape($this->othersVal)=='Y'){echo "checked";}?>><?php echo $this->escape($this->others);?>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<?php 
//							$captcha = new Zend_Form_Element_Captcha( 'captcha', array(
//							  'label' => '請輸入以下5個字母',
//							  'name' => 'captcha', //回傳post欄位的名稱
//							  'required' => true,
//							  'captcha' => array('captcha' => 'Figlet', 'wordLen' => 5, 'timeout' => 300)
//							));
//							echo $captcha;
							$CHALLENGE_FIELD_PARAM_NAME = "verificationCode";
						?>
						<label for="subject">請輸入驗證碼:</label>
						<input type="text" 
							name="<?php echo($CHALLENGE_FIELD_PARAM_NAME) ?>" 
							id="<?php echo($CHALLENGE_FIELD_PARAM_NAME) ?>" 
							maxlength="<?php echo($CHALLENGE_STRING_LENGTH) ?>" 
							size="<?php echo($CHALLENGE_STRING_LENGTH) ?>" 
							class="inputText" />
						<img src="/function/DRBImageVerification/getimage.php" />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<input id="btnBack2" class="yellow-button" type="button" value="<?php echo $this->escape($this->back);?>">
						<input type="submit" class="yellow-button" value="<?php echo $this->escape($this->submit);?>"/>
					</td>
				</tr>
			</table>
		</form>
	</div>
	<?php require_once '/template/right-sidebar.phtml';?>
</div>
